home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
vmed.arc
/
ED5.CCC
< prev
next >
Wrap
Text File
|
1985-12-03
|
4KB
|
161 lines
/* Screen editor: output format module
*
* Module: ed5/ccc
* Date: November 12, 1983
* Changed: February 16, 1984
*/
#include ed0
/* data global to this module */
/* auto horizontal scroll will require additions:
#option zvar ON
int fmtlmar; /* first column displayed
#option zvar OFF
fmtslm(n) int n; /* set left margin to 'n' */
/* define length of a tab character */
char fmttab;
/* define the current device and device width */
char fmtdev; /* device -- YES/NO = LIST/CONSOLE */
char fmtwidth; /* device width. LISTW/SCRNW1 */
/* fmtcol[i] is the first column at which
* buf[i] will be printed.
* fmtsub() and fmtlen() assume fmtcol[] is valid
* on entry.
*/
int fmtcol[MAXLEN1];
/* direct output from this module to either the
* console or the list device.
*/
fmtassn(listflag) char listflag;
{ if (listflag == YES) {
fmtdev = YES;
fmtwidth = LISTW;
}
else {
fmtdev = NO;
fmtwidth = SCRNW1;
}
}
/* adjust fmtcol[] to prepare for calls on
* fmtout() and fmtlen()
*
* NOTE: this routine is needed for efficiency.
* Without fmtadj(), calls on fmtlen() become too slow.
*/
fmtadj(buf,minind,maxind) char *buf; int minind,maxind;
{ int k;
/* line always starts at left margin */
fmtcol[0] = 0;
/* start scanning at minind */
k = minind;
while (k < maxind) {
if (buf[k] == CR)
break;
fmtcol[k+1]=fmtcol[k]+fmtlench(buf[k],fmtcol[k]);
++k;
}
}
/* return column at which buf[i] will be printed */
fmtlen(buf,i) char *buf; int i;
{ return(fmtcol[i]); } /* -fmtlmar */
/* print buf[i] ... buf[j-1] on current device so long
* as characters will not be printed in last column.
*/
fmtsubs(buf,i,j) char *buf; int i,j;
{ int k;
if (fmtcol[i] >= fmtwidth) /* -fmtlmar */
return;
outxy(fmtcol[i],outgety()); /* position cursor */
while (i < j) {
if (buf[i] == CR)
break;
if (fmtcol[i+1] > fmtwidth) /* -fmtlmar */
break;
fmtoutch(buf[i],fmtcol[i]); /* -fmtlmar */
++i;
}
outdeol(); /* clear rest of line */
}
/* print string which ends with CR or EOS to current
* device. Truncate the string if it is too long.
*/
fmtsout(buf,offset) char *buf; int offset;
{ char c;
int col,k;
col = 0; /* -fmtlmar */
while (c = *buf++) {
if (c == CR)
break;
k = fmtlench(c,col);
if ((col+k+offset) > fmtwidth)
break;
fmtoutch(c,col); /* only if positive */
col = col + k;
}
}
/* return length of char c at column col */
fmtlench(c,col) char c; int col;
{ if (c == TAB) {
/* tab every fmttab columns */
return(fmttab - (col%fmttab));
}
else if (c < 32) {
/* control char */
return(2);
}
else return(1);
}
/* output one character to current device.
* convert tabs to blanks.
*/
fmtoutch(c,col) char c; int col;
{ int k;
if (c == TAB) {
k = fmtlench(TAB,col);
while ((k--) > 0 )
fmtdevch(' '); /* if (++col > 0) ... */
}
else if (c < 32) {
fmtdevch('^'); /* same test ... */
fmtdevch(c + 64); /* same test ... */
}
else fmtdevch(c); /* same test ... */
}
/* output character to current device */
fmtdevch(c) char c;
{ if(fmtdev == YES)
syslout(c);
else outchar(c);
}
/* output a CR and LF to the current device */
fmtcrlf()
{ if (fmtdev == YES)
syslout(CR);
else {
/* kludge: this should be in out module */
/* make sure out module knows position */
outxy(0,SCRNL1);
syscout(CR);
}
}
/* set tabs at every n columns */
fmtset(n) char n;
{ fmttab = max(1,n); }
/* end module ed5/ccc */